package migrations

import (
	"github.com/goravel/framework/contracts/database/schema"
	"github.com/goravel/framework/facades"
)

type M20250224102854CreatePermissionsTable struct {
}

// Signature The unique signature for the migration.
func (r *M20250224102854CreatePermissionsTable) Signature() string {
	return "20250224102854_create_permissions_table"
}

// Up Run the migrations.
func (r *M20250224102854CreatePermissionsTable) Up() error {
	if !facades.Schema().HasTable("permissions") {
		return facades.Schema().Create("permissions", func(table schema.Blueprint) {
			table.ID()
			table.UnsignedBigInteger("pid").Nullable()
			table.String("code")
			table.String("label")
			table.Enum("type", []any{"menu", "button"}).Default("menu")
			table.Timestamps()
			table.SoftDeletes("deleted_at")
		})
	}

	return nil
}

// Down Reverse the migrations.
func (r *M20250224102854CreatePermissionsTable) Down() error {
	return facades.Schema().DropIfExists("permissions")
}
